<?php
/*
 * @Author: your name
 * @Date: 2021-11-04 16:42:10
 * @LastEditTime: 2021-11-22 11:34:51
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \property\app\Http\Controllers\admin_controller\Teaching.php
 */

namespace App\Http\Controllers\admin_controller;

use Illuminate\Support\Facades\Request;
use App\Models\admin_model\TeachingCulture;
// use App\Models\admin_model\Admins;                        // admins表
// use App\Models\admin_model\Column;                        // admins表
// use App\Http\Controllers\redis\RedisController as Redis;  //redis 缓存

class Teaching extends BaseController
{
    /**
     * @description: 教培公司列表
     */
    public function teachingList()
    {

        if (Request::has('keyWord')) {
            $whereStr = '';
            $limitStr = '';
            if (Request::input('pageSize') && Request::input('page')) {
                $limitStr =   limit_joint(Request::input('page'), Request::input('pageSize'));
            }
            $keyWord = array_filter(Request::input('keyWord'), 'filtrfunction');
            if (!empty($keyWord)) {
                $whereStr .= havaWhereLikeJoinEqual($keyWord);
            }
            $teachingList  =   TeachingCulture::teachingList($whereStr, $limitStr);
            $teachingCount =   TeachingCulture::teachingCount($whereStr);

            return $this->create(200, '查询成功', ['list' => $teachingList, 'total' => $teachingCount[0]['count']]);
        } else {
            return missingParameter();
        }

       
    }

    public function teachingGoupBy()
    {
        $teachingClass =  TeachingCulture::teachingClass();
        return $this->create(200, '查询成功', $teachingClass);
    }
    

    public function teachingAdd(){
        if(Request::has('formData')){
            $formData = Request::input('formData');
            $res =  redis_mysql_add_return('teaching_culture',$formData);
            if($res){
                return $this->create(200,'添加成功',['id'=>$res]);
            }else{
                return $this->create(100,'添加失败');
            }
        }
    }

    public function teachingUpdate()
    {
        if (Request::has('formData') && Request::has('id')) {
            $formData = Request::input('formData');
            $id       = Request::input('id');
            if(is_array($id)){
                $res = redis_mysql_edit_in('teaching_culture',$id,$formData);
            }else{
                $res =  redis_mysql_edit_return('teaching_culture', ['id' => $id], $formData);
            }
            if ($res) {
                return $this->create(200, '修改成功');
            } else {
                return $this->create(100, '修改失败');
            }
        }
    }


    public function teachingSelOne(){
        if(Request::has('id')){
         $res =   redis_mysql_selone_return('teaching_culture',Request::input('id'),false);
         
         return $this->create(200,'查询成功',$res);
        }
    }
}
